<template>
	<view class="page-my-quote">
		<view class="page-list">	
			<!-- 列表组件 -->
			<block v-for="(item,index) in resData.list" :key="index">
				<my-quote-item :listsData="item" :data="item.quoteDemandVo"   infoIcon="../../static/ibs/img_comm_closed.png"></my-quote-item>
				<trade-item  :data="item.quoteDemandVo" :params="params" @OnQuote="OnQuote"  :optionMethod="callQoute"
							 :hideQuote=true infoIcon="../../static/ibs/img_comm_closed.png" :showplaceholder=true ></trade-item>
			</block>
			<view class="no-result" v-if="noData">
				<image src="../../static/ibs/img_home_empty.png"  mode="aspectFill"/>
				<text>暂无我的报价</text>
			</view>
<!-- 			<block v-for="(item,index) in resData.list" :key="index">
				<my-quote-items :data="item" :params="params" @OnQuote="onQuote" @OnseeInfo="OnseeInfo" :optionParam="optionParam" infoIcon="../../static/ibs/img_comm_closed.png"></my-quote-items>
			</block> -->
		</view>
		<!-- 加载更多组件 -->
		<load-more  :loadingType="loadingType" :showImage="showImage" :contentText="contentText">{{searchNoData}}</load-more>
        <!-- 支付弹层 -->
        <pay-box v-if="isShowpayBox"  @closeInfo="closeInfo"  :unreadQuote="unreadQuote" :demandInfo="demandInfo"  remoteUrl="/wechat/demand/unifiedOrder"></pay-box>
        <!-- 支付成功弹层 -->
        <pay-success v-if="isShowpaySuccessBox"  @closeInfo="closeInfo"  :demandInfo="demandInfo"  remoteUrl="/wechat/demand/unifiedOrder"></pay-success>
	</view>
</template>

<script >
	import MyQuoteItem from '@/components/ibs/myQuoteItem.vue';
	import tradeItem from '@/components/ibs/tradeItem.vue';
	import loadMore from '@/components/loadMore.vue' //调用列表上拉更新数据组件
	import sysEnum from '@/common/sysEnum.js';
	import publicMethod from '@/common/publicMethod.js';
	import quoteBox from '@/components/form/quoteBox.vue'  //报价弹层
	import payBox from '@/components/form/pay.vue'  //报价弹层
  import paySuccess from '@/components/form/paySuccess.vue'  //报价弹层
	import api from '@/common/api.js';   //请求API方法	
	import {wxSetting,wxAuthorize} from '../../common/wxApi.js';
	export default {
		components: {
			MyQuoteItem,
			loadMore,
			payBox,
			paySuccess,
			quoteBox,
			tradeItem

		},
		data() {
			return {
				showImage: false,
				loadingType: 0,
				quoteId: false, //报价ID
				isShowpayBox: false, //微信支付弹窗
				isShowpaySuccessBox: false,
				demandId: false, //报价ID
				demandInfo:{},  //求购信息
				unreadQuote: null,  //未读报价
				contentText: {
					contentdown: "",
					contentrefresh: "正在加载...",
					contentnomore: ""
				},
				currentScrollTop: 0,
				scrollHeight: '',
				isSearchflxed: false,
				bannerHeight: 346,
				
				params: [{
						label: '采购意向价格',
						key: 'intentPrice'
					},
					{
						label: '买家联系方式',
						key: 'contactMobileNo'
					},
					 {
						type: Boolean,
						default: false
					},
					{
					    label: '要求',
					    key: 'remarkDemand'
					},
					
				],
				optionParam: {
						optionClass: [''],
					    label: '查看',
						labelClass: [''],
						optionClick: this.callQoute
				},
				resData: {
					pageNum:  1,
					total: 0,
					list: []
				},
				noData: null, // 是否没有数据
				hasMore: false // 判断是否还有更多数据
			};
		
		},
		//下拉刷新
		onPullDownRefresh() {
			this.hasMore = false;
			this.noData = false;
			this.loadingType = 0;
			this.getData();
		},
		//上拉加载更多
		onReachBottom() {
			if (this.loadingType !== 0) {
				return;
			}
			if (this.noData) {
				return;
			}
			if (!this.hasMore && this.resData.pageNum === 1) { // 如果当前也是第一页且没有更多数据了则禁止上拉
				return;
			}
			if (!this.hasMore && this.resData.pageNum > 1) { // 如果当前页数不是第一页且没有更多数据了则显示没有已全部加载完成
				this.loadingType = 2;
				return;
			}
			if (this.hasMore) {
				this.loadingType = 1;
			}
			setTimeout(() => {
				this.addData();
			}, 1200);
		},
		onLoad(){
			let that = this;
			that.getData();
		},
		methods: {
			//初始化获取数据 及搜索访求
			getData() {
				let that = this;
				//调用请求数据方法
				var url = "/wechat/user/myQuote"; //请求的URL
				var params = {};
				api.httpRequest(url, params, "POST",true).then((res) => {
					that.resData.list = res.result.list; //获取列表数据
					that.resData.pageNum = res.result.pageNum; //获取当前页
					that.resData.total = res.result.total; //获取总页数，加载更多会用到
					if(res.result.total==0){   //如果列表就跳转到制作初始页
					   that.noData=true;
					}else{
			            that.noData=false;
					}
				});
			},
			
			/*
			滑到最底部时触发（上拉更多）方法
			*/
			async addData() {
			    if (this.resData.list.length >= this.resData.total) {  //当前页面中的数据列表大于或者等于数据库中total时，直接返回
					this.loadingType = 2;
                    return;
				} else {
					let that = this;
					this.loadingType = 1;  //状态加载中
					var url = "/wechat/user/myQuote";   //请求地址
					var params = {
						pageNum: this.resData.currentPage + 1    //传请求的页数,
					};
                await  api.httpRequest(url, params, "post").then((res) => {
                    if (res.code !== 200) {
                        that.showToast(res.message);
                        return;
                    }
                    that.resData.list = that.resData.list.concat(res.result.list);
                    that.resData.currentPage = res.result.pageNum;
                    that.resData.total = res.result.total;  //获取总页数，加载更多会用到
                    that.hasMore = res.result.hasNextPage;
                    this.loadingType = 0;
                });
            }
			},
			//报价弹窗
			OnQuote(id){
				let that=this;
				that.isShowQuoteBox=true;
				that.quoteId=id;
			
			},

			//关闭完善资料窗口
            closeInfo(val) {
                let that = this;
                console.log("closeInfo==========", val);
                if (val == "quoteBox") {
                    that.isShowQuoteBox = false; //关闭报价弹窗口
                } else if (val == "infoBox") {
                    that.isShowInfoBox = false; //关闭完善弹窗口
                } else if (val == "payBox") {
                    that.isShowpayBox = false;  //关闭支付弹窗口
                } else if (val == "paySuccessBox") {
                    that.isShowpaySuccessBox = false;  //关闭支付成功弹窗口
                }
            },
             //查看报价/ 拨打电话
			callQoute(data) {
				let that=this;
				that.demandInfo=data;
				that.demandInfo.id = data.demandId;
				that.callQouteFn(data)
			}
		}
	}
</script>

<style>
	.page-my-quote{
		background: #f2f2f5;
		width: 100vw;
		min-height: 100vh;
		/* padding-top:20upx; */
	}
    .components-trade-item{
		border-top:none;
		margin-bottom: 20upx;
	}
	.page-list{
		padding-top: 20upx;
		margin-left: 24upx;
		margin-right: 24upx;
		
	}
	.no-result{
		background: #f5f6f7;
		width: 100%;
		height: 100%;
		top: 50%;
		left: 50%;
		-webkit-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%);
		text-align: center;
		overflow: hidden;
		position: fixed;
	}
	.no-result image{
		width: 200upx;
		height: 200upx;
		display: block;
		margin:0 auto;
		margin-top:32vh;
	}
</style>
